<?php
use think\Db;
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------
// 应用公共文件

/**
 * 模拟tab产生空格
 * @param int $step
 * @param string $string
 * @param int $size
 * @return string
 */
function tab($step = 1, $string = ' ', $size = 4) {
    return str_repeat($string, $size * $step);
}


function getfirstchar($s0) {
    if ($s0[0] == 'I' || $s0[0] == 'i') {
        return "I";
    } elseif ($s0[0] == 'U' || $s0[0] == 'u') {
        return 'U';
    } elseif ($s0[0] == 'V' || $s0[0] == 'v') {
        return 'V';
    } elseif (is_numeric($s0[0])) {
        return $s0[0];
    } else {
        $fchar = ord($s0{0});
        if ($fchar >= ord("A") and $fchar <= ord("z"))
            return strtoupper($s0{0});
        $s1 = iconv("UTF-8", "gb2312", $s0);
        $s2 = iconv("gb2312", "UTF-8", $s1);
        if ($s2 == $s0) {
            $s = $s1;
        } else {
            $s = $s0;
        } $asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
        if ($asc >= -20319 and $asc <= -20284)
            return "A";
        if ($asc >= -20283 and $asc <= -19776)
            return "B";
        if ($asc >= -19775 and $asc <= -19219)
            return "C";
        if ($asc >= -19218 and $asc <= -18711)
            return "D";
        if ($asc >= -18710 and $asc <= -18527)
            return "E";
        if ($asc >= -18526 and $asc <= -18240)
            return "F";
        if ($asc >= -18239 and $asc <= -17923)
            return "G";
        if ($asc >= -17922 and $asc <= -17418)
            return "H";
        if ($asc >= -17417 and $asc <= -16475)
            return "J";
        if ($asc >= -16474 and $asc <= -16213)
            return "K";
        if ($asc >= -16212 and $asc <= -15641)
            return "L";
        if ($asc >= -15640 and $asc <= -15166)
            return "M";
        if ($asc >= -15165 and $asc <= -14923)
            return "N";
        if ($asc >= -14922 and $asc <= -14915)
            return "O";
        if ($asc >= -14914 and $asc <= -14631)
            return "P";
        if ($asc >= -14630 and $asc <= -14150)
            return "Q";
        if ($asc >= -14149 and $asc <= -14091)
            return "R";
        if ($asc >= -14090 and $asc <= -13319)
            return "S";
        if ($asc >= -13318 and $asc <= -12839)
            return "T";
        if ($asc >= -12838 and $asc <= -12557)
            return "W";
        if ($asc >= -12556 and $asc <= -11848)
            return "X";
        if ($asc >= -11847 and $asc <= -11056)
            return "Y";
        if ($asc >= -11055 and $asc <= -10247)
            return "Z";
        return null;
    }
}

/* 获取缓存函数 */

function cache_read($file, $dir = '', $mode = '') {
    $file = $dir ? DT_CACHE . '/' . $dir . '/' . $file : DT_CACHE . '/' . $file;
    if (!is_file($file))
        return $mode ? '' : array();
    return $mode ? file_get($file) : include $file;
}

/* 获取缓存写入函数 */

function cache_write($file, $string, $dir = '') {
    if (is_array($string))
        $string = "<?php defined('IN_DESTOON') or exit('Access Denied'); return " . strip_nr(var_export($string, true)) . "; ?>";
    $file = $dir ? DT_CACHE . '/' . $dir . '/' . $file : DT_CACHE . '/' . $file;
    $strlen = file_put($file, $string);
    return $strlen;
}

/* 删除缓存函数 */

function cache_delete($file, $dir = '') {
    $file = $dir ? DT_CACHE . '/' . $dir . '/' . $file : DT_CACHE . '/' . $file;
    return file_del($file);
}

/* 清空缓存函数 */

function cache_clear($str, $type = '', $dir = '') {
    $dir = $dir ? DT_CACHE . '/' . $dir . '/' : DT_CACHE . '/';
    $files = glob($dir . '*');
    if (is_array($files)) {
        if ($type == 'dir') {
            foreach ($files as $file) {
                if (is_dir($file)) {
                    dir_delete($file);
                } else {
                    if (file_ext($file) == $str)
                        file_del($file);
                }
            }
        } else {
            foreach ($files as $file) {
                if (!is_dir($file) && strpos(basename($file), $str) !== false)
                    file_del($file);
            }
        }
    }
}

/* 获取网站配置信息 */

function get_setting($item = null) {
    $model = new \app\common\model\Setting();
    $result = $model->getSetting($item);
    return $result = setting_to_key($result);
}

/* 获取网站配置俱体信息 */

function get_setting_value($item, $itemkey) {
    if (empty($item) || empty($itemkey))
        return '';
    $model = new \app\common\model\Setting();
    $result = $model->getSettingValue($item, $itemkey);
    return $result;
}

/* 转换setting 以 item 作为数组键值 */

function setting_to_key($arr) {
    if (!is_array($arr))
        return array();
    $result = array();
    foreach ($arr as $v) {
        $result[$v['item']][$v['item_key']] = $v['item_value'];
    }
    return $result;
}

/* * 通过后缀做标记* */

function file_type($val) {
    $rype = [
        'rmvb' => 'video',
        '3gp' => 'audio',
        'oog' => 'audio',
        'mp4' => 'video',
        'avi' => 'video',
        'flv' => 'video',
        'wav' => 'video',
        'gif' => 'img',
        'jpg' => 'img',
        'png' => 'img',
        'bmp' => 'img',
        'ico' => 'img',
    ];
    if (empty($rype[$val]))
        $rype[$val] = 'download';
    return $rype[$val];
}



function antecedents($val, $aims) {
    $origin = $_SERVER['REQUEST_URI'];
    $min = stripos($origin, '.');
    if ($min > 1) {
        $origin = substr($origin, 0, $min) . '.html';
    }
    $origin = str_replace($val, $aims, $origin);
    return $origin;
}
function scores($val, $statu = 0){
        $rype = [
        '1' => '1',
        '2' => '2',
        '3'=>'3'
    ];
    if ($statu) {
        return $rype;
    }
    if (empty($rype[$val]))
        $rype[$val] = '未知';
    return $rype[$val];
}
function practice($val, $statu = 0) {
    $rype = [
        '1' => '日常练习',
        '2' => '培训室配比练习',
        '3'=>'学习中心反馈',
        '4'=>'试卷',
    ];
    if ($statu) {
        return $rype;
    }
    if (empty($rype[$val]))
        $rype[$val] = '未知';
    return $rype[$val];
}

function feedback($val, $statu = 0) {
    $rype = [
        '1' => '日常安全',
        '2' => '技术交底',
        '3' => '安全检查',
        '4' => '工程管理',
        '5' => '违章处罚',

    ];
    if ($statu) {
        return $rype;
    }
    if (empty($rype[$val]))
        $rype[$val] = '未知';
    return $rype[$val];
}

//计算时间戳距现在时差
function time2Units($time) {
    $year = floor($time / 60 / 60 / 24 / 365);
    $time -= $year * 60 * 60 * 24 * 365;
    $month = floor($time / 60 / 60 / 24 / 30);
    $time -= $month * 60 * 60 * 24 * 30;
    $week = floor($time / 60 / 60 / 24 / 7);
    $time -= $week * 60 * 60 * 24 * 7;
    $day = floor($time / 60 / 60 / 24);
    $time -= $day * 60 * 60 * 24;
    $hour = floor($time / 60 / 60);
    $time -= $hour * 60 * 60;
    $minute = floor($time / 60);
    $time -= $minute * 60;
    $second = $time;
    $elapse = '';

    $unitArr = array('年' => 'year', '个月' => 'month', '周' => 'week', '天' => 'day',
        '小时' => 'hour', '分钟' => 'minute', '秒' => 'second'
    );

    foreach ($unitArr as $cn => $u) {
        if ($ $u > 0) {
            $elapse = $ $u . $cn;
            break;
        }
    }

    return $elapse;
}

function inter_sub($val){
	$val = strip_tags($val);
	if(strlen($val)>50){
		$val = mb_substr($val,0,50,'utf-8').'...';
	}
return $val;
	
}

function stropee($value)
{
    $url = substr($value,0,2);
   if($url!='..' && $url!='ht'){
	   return 1;
   } else {
	   return 0;
   }
}


function i_array_column($input, $columnKey, $indexKey = null)
{
    if (!function_exists('array_column')) {
        $columnKeyIsNumber = (is_numeric($columnKey)) ? true : false;
        $indexKeyIsNull = (is_null($indexKey)) ? true : false;
        $indexKeyIsNumber = (is_numeric($indexKey)) ? true : false;
        $result = array();
        foreach ((array) $input as $key => $row) {
            if ($columnKeyIsNumber) {
                $tmp = array_slice($row, $columnKey, 1);
                $tmp = (is_array($tmp) && !empty($tmp)) ? current($tmp) : null;
            } else {
                $tmp = isset($row[$columnKey]) ? $row[$columnKey] : null;
            }
            if (!$indexKeyIsNull) {
                if ($indexKeyIsNumber) {
                    $key = array_slice($row, $indexKey, 1);
                    $key = (is_array($key) && !empty($key)) ? current($key) : null;
                    $key = is_null($key) ? 0 : $key;
                } else {
                    $key = isset($row[$indexKey]) ? $row[$indexKey] : 0;
                }
            }
            $result[$key] = $tmp;
        }
        return $result;
    } else {
        return array_column($input, $columnKey, $indexKey);
    }

}


/*
@ 创建文件，根据地址创建文件
@param $source  源地址
@param $fileOutPath 输出路径
@param $model true:返图片文件内容，false:返回地址
@return 反回创建文件的地址或者内容
*/
function createLocalFile($sourceFileName,$fileOutPath,$model=false){

    if(empty($sourceFileName)) return false;
    //获取文件名1
    $arr_temp = explode('/', $sourceFileName);
    $fileNameExt = end($arr_temp);
    $fileName = explode('.', $fileNameExt);
    
    $ext = end($fileName);
    $fileName = $fileName[0];
    $fileOutPath = $fileOutPath;
    if(!file_exists($fileOutPath)) mkdir($fileOutPath,0777,true);
    $fileOutPath =  realpath($fileOutPath);
    if($t = strpos($fileOutPath, '\\')){
        $filePathName = substr_replace($fileOutPath, '\\', $t,2);
    }
    $filePathName = $fileOutPath.'/'. time() .'_'.$fileName.'.' . $ext;
    $source = file_get_contents($sourceFileName);
    file_put_contents($filePathName,$source);
    if($model) return $source;
    return $filePathName;        
}


/****
*array_sorting 二维数组指定排序
*$Sorting 以字段排序
*$arr 需要重排的原始数组
*$sort 排序规则
***/

function arraySorting($sorting,$arr,$sort='asc'){
	$sequence = ['asc'=>SORT_ASC,'desc'=>SORT_DESC];
	if(empty($sequence[$sort])){
		return $arr;
	}
	
	$flag = array();  
  
	foreach($arr as $v){  
		$flag[] = $v[$sorting];  
	}
	  
	array_multisort($flag, $sequence[$sort], $arr);
	return $arr;

}

/**
 * 递归无限级分类【先序遍历算】，获取任意节点下所有子孩子
 * @param array $arrCate 待排序的数组
 * @param int $parent_id 父级节点
 * @param int $level 层级数
 * @return array $arrTree 排序后的数组
 */
function getMenuTree($arrCat, $parent_id = 0, $level = 0)
{
    static  $arrTree = array(); //使用static代替global
    if( empty($arrCat)) return false;
    $level++;
    foreach($arrCat as $key => $value)
    {
        if($value['parent_id' ] == $parent_id)
        {
            $value['level'] = $level;
            $arrTree[] = $value;
            unset($arrCat[$key]); //注销当前节点数据，减少已无用的遍历
            getMenuTree($arrCat, $value[ 'id'], $level);
        }
    }

    return $arrTree;
}

/**
 * 无限极分类，传递一个子ID得到所有父集
 * @param $data
 * @param $id
 * @return array
 */
function getParents($data,$id){
    $arr=array();
    foreach ($data as $v) {
        if ($v['id']==$id) {
            $arr[]=$v['admin_reg'];
            $arr=array_merge(getParents($data,$v['pid']),$arr);
        }
    }
    return $arr;
}
/*
*子平台找父平台
*
*/
function getSonAdminRegByPlaformId($plaformId,$type=1){
    if (empty($_SESSION['think']['reg'])){
        return [0];
    }
    if(empty($plaformId)){
        $admin_regs = [$_SESSION['think']['reg']];
    }else{
        $admin_regs = [];
        $result = Db::name('plaform')->field('id,parentid parent_id,admin_reg,level')->where(['status'=>1])->select();

        $childs = getParents($result,$plaformId);
		
        if (!empty($childs)){
            $admin_regs = array_column($childs,'admin_reg');
            $admin_regs = array_unique($admin_regs);
        }
        if ($type==1){
            array_push($admin_regs,$_SESSION['think']['reg']);
        }
    }
    return $admin_regs;

}

/**
 * 获取一级地区列表
 * @param null $id
 */
function getAreaList($id=null){
    $reg = Db::name('admin_user')->field('reg')->where("id='1'")->find();
        return Db::name('area')->where("admin_reg='{$reg['reg']}' ")->select();
}

function getParentAdminRegByPlaformId($plaformId,$type=1){
    if (empty($_SESSION['think']['reg'])){
        return [0];
    }
    if(empty($plaformId)){
        $admin_regs = [$_SESSION['think']['reg']];
    }else{
        $admin_regs = [];
        $result = Db::name('plaform')->field('id,parentid parent_id,admin_reg,level')->where(['status'=>1])->select();
        $Parents = getParents($result,$plaformId);
        if (!empty($Parents)){
            $admin_regs = array_column($Parents,'admin_reg');
            $admin_regs = array_unique($admin_regs);
        }
        if ($type==1){
            array_push($admin_regs,$_SESSION['think']['reg']);
        }
    }
    return $admin_regs;

}

function getChildAdminRegByPlaformId($plaformId,$type=1){
    if (empty($_SESSION['think']['reg']) && $type!=9){
        return [0];
    }
	$parentids = Db::name('plaform')->field('parentid')->where(['admin_reg'=>$_SESSION['think']['reg']])->find();

	
    if(empty($plaformId) || $parentids["parentid"]){
        $admin_regs = [$_SESSION['think']['reg']];
    }else{
        $admin_regs = [];
        $result = Db::name('plaform')->field('id,parentid parent_id,admin_reg,level')->where(['status'=>1])->select();

        $childs = getMenuTree($result,$plaformId);
        if (!empty($childs)){
            $admin_regs = array_column($childs,'admin_reg');
            $admin_regs = array_unique($admin_regs);
        }
        if ($type==1){
            array_push($admin_regs,$_SESSION['think']['reg']);
        } else if ($type==3){
			 $result = Db::name('plaform')->field('parentid')->where(['admin_reg'=>$_SESSION['think']['reg']])->find();
			 
			 if(!empty($result['parentid'])){
				$results = Db::name('plaform')->field('admin_reg')->where(['id'=>$result['parentid']])->find();
				$admin_regs[] = $results['admin_reg'];
			 }
			 	$admin_regs[] = $_SESSION['think']['reg'];
	
		}
    }
    return $admin_regs;

}

function getChildAdminRegByPlaformIdUp($plaformId){
    if (empty($_SESSION['think']['reg'])){
        return [0];
    }
	$admin_regs = [$_SESSION['think']['reg']];
    if(!empty($plaformId)){

        $result = Db::name('plaform')->field('id,parentid parent_id,admin_reg,level')->where(['status'=>1,'id'=>$plaformId])->find();
		if(!empty($result['admin_reg']) && $result['parent_id']){
			$result = Db::name('plaform')->field('admin_reg')->where(['id'=>$result['parent_id']])->find();
			$admin_regs[] = $result['admin_reg'];
		}
     
      
    }
    return $admin_regs;

}

function cur_post($url = '',$ispost=true, $post_data = array(),$type=0,$hosts='http://uc.api.gandianli.com/') {
        if (empty($url) || empty($post_data)) {
            return false;
        }
        $o = "";
        if($ispost){
            $url=$hosts.$url;
        }else{
            $url =$hosts.$url.'?'.$post_data;
        }
		
		if($type){
			$curlPost =$post_data;
		} else {
			$curlPost = ['key'=>$post_data,'ngis'=>md5($post_data.'as')];
		}
        header("Content-type: text/html; charset=utf-8");
        $ch = curl_init();//初始化curl
        curl_setopt($ch, CURLOPT_URL,$url);//抓取指定网页
		curl_setopt($ch, CURLOPT_REFERER, 'https://agk.gandianli.com'); 
        curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
		curl_setopt($ch, CURLOPT_TIMEOUT,3);//设置3秒钟 如果3秒没有返回直接丢失
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
        if($ispost){
            curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
            curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
        }
		
        $data = curl_exec($ch);//运行curl
        curl_close($ch);

        return json_decode($data);
}

function OperDeploy($data,$status){
	$address_path = dirname(dirname(__FILE__)).'/mydeploy/';
	switch($status)
		{
		case 'newupdate':
		$paths = $address_path.'newupdate.php';
		$conf_content = "<?php \r\n";
		$conf_content .= "\$ver_c[\"version\"]='".$data['item_key']."'; \r\n";
		$conf_content .= "\$ver_c[\"anz\"]='".$data['anz']."'; \r\n";
		$conf_content .= "\$ver_c[\"ios\"]='".$data['ios']."'; \r\n";
		$conf_content .= "\$ver_c[\"content\"]='".$data['content']."'; \r\n";
		$conf_content .= " ?>";
		file_put_contents($paths,$conf_content);
		  
		  break;  
		case 'addres':
			return $address_path;
		break; 
		}
	
}

function secsToStrws($secs) {
        if ($secs >= 86400) {
            $days = floor($secs / 86400);
            $secs = $secs % 86400;
            $r = $days . ' day';
            if ($days <> 1) {
                $r .= '';
            }
            if ($secs > 0) {
                $r .= ' ';
            }
        }
        if ($secs >= 3600) {
            $hours = floor($secs / 3600);
            $secs = $secs % 3600;
            $r .= $hours . '时';
            if ($hours <> 1) {
                $r .= '';
            }
            if ($secs > 0) {
                $r .= ' ';
            }
        }
        if ($secs >= 60) {
            $minutes = floor($secs / 60);
            $secs = $secs % 60;
            $r .= $minutes . '分';
            if ($minutes <> 1) {
                $r .= '';
            }
            if ($secs > 0) {
                $r .= '';
            }
        }
        $r .= $secs;
        if ($secs <> 1) {
            $r .= '秒';
        }
        return $r;
    }
	
	
	
	
	/*****创建文件夹****/
	function mkdirs($dir, $mode = 0777)
	{
    if (is_dir($dir) || @mkdir($dir, $mode)) return TRUE;
    if (!self::mkdirs(dirname($dir), $mode)) return FALSE;
    return @mkdir($dir, $mode);
	}
	
	function tab_con($dir,$cid)
	{
				$Listtme = dirname(dirname(__FILE__)).'/files/tempnam/'.$cid.'/';//保存总目录
				$this->mkdirs($Listtme);
				$Listdivision = $Listtme. iconv('UTF-8', 'GB2312', $dir).'/';//保存总目录
				$this->mkdirs($Listdivision);
	}
	
	/*****创建文件夹 end****/
	
		/*****打包 ****/
	//linux需开启zlib，windows需取消php_zip.dll前的注释

       /**
         * PHP ZipArchive压缩文件夹，实现将目录及子目录中的所有文件压缩为zip文件
         * @author
         * @param string $folderPath 要压缩的目录路径
         * @param string $zipAs 压缩文件的文件名，可以带路径
         * @return bool 成功时返回true，否则返回false
         */
        function zipFolder($folderPath, $zipAs){
                $folderPath = (string)$folderPath;
                $zipAs = (string)$zipAs;
                if(!class_exists('ZipArchive')){
                        return false;
                }
                if(!$files=scanFolder($folderPath, true, true)){
                        return false;
                }
                $za = new ZipArchive;
                if(true!==$za->open($zipAs, ZipArchive::OVERWRITE | ZipArchive::CREATE)){
                        return false;
                }
                $za->setArchiveComment(base64_decode('LS0tIHd1eGlhbmNoZW5nLmNuIC0tLQ=='));
                foreach($files as $aPath => $rPath){
                        $za->addFile($aPath, $rPath);
                }
                if(!$za->close()){
                        return false;
                }
                return true;
        }

        /**
         * 扫描文件夹，获取文件列表
         * @author
         * @param string $path 需要扫描的目录路径
         * @param bool   $recursive 是否扫描子目录
         * @param bool   $noFolder 结果中只包含文件，不包含任何目录，为false时，文件列表中的目录统一在末尾添加/符号
         * @param bool   $returnAbsolutePath 文件列表使用绝对路径，默认将返回相对于指定目录的相对路径
         * @param int    $depth 子目录层级，此参数供系统使用，禁止手动指定或修改
         * @return array|bool 返回目录的文件列表，如果$returnAbsolutePath为true，返回索引数组，否则返回键名为绝对路径，键值为相对路径的关联数组
         */
        function scanFolder($path='', $recursive=true, $noFolder=true, $returnAbsolutePath=false,$depth=0){
                $path = (string)$path;
                if(!($path=realpath($path))){
                        return false;
                }
                $path = str_replace('\\','/',$path);
                if(!($h=opendir($path))){
                        return false;
                }
                $files = array();
                static $topPath;
                $topPath = $depth===0||empty($topPath)?$path:$topPath;
                while(false!==($file=readdir($h))){
                        if($file!=='..' && $file!=='.'){
                                $fp = $path.'/'.$file;
                                if(!is_readable($fp)){
                                        continue;
                                }
                                if(is_dir($fp)){
                                        $fp .= '/';
                                        if(!$noFolder){
                                                $files[$fp] = $returnAbsolutePath?$fp:ltrim(str_replace($topPath,'',$fp),'/');
                                        }
                                        if(!$recursive){
                                                continue;
                                        }
                                       $function = __FUNCTION__;
                                        $subFolderFiles = scanFolder($fp, $recursive, $noFolder, $returnAbsolutePath, $depth+1);
                                        if(is_array($subFolderFiles)){
                                                $files = array_merge($files, $subFolderFiles);
                                        }
                                }else{
                                        $files[$fp] = $returnAbsolutePath?$fp:ltrim(str_replace($topPath,'',$fp),'/');
                                }
                        }
                }
                return $returnAbsolutePath?array_values($files):$files;
        }



		function zip_bale($cid){
			ini_set('max_execution_time',0);// 不限制执行时间
			ini_set('memory_limit',-1);// 不限制内存使用
			$filePath = $cid;
			$aa = date("Y_m_d_H_i_s") .'.zip';
			$zipFileName = dirname(dirname(__FILE__)).'/public/static/admin/rar/'.$aa;
		   if(zipFolder($filePath,$zipFileName)){
					return $aa;

			}else{
					return 'n';
			}
		
		}
	/*****打包  end****/
	
	/****删除指定目录下所有文件****/
		function delFile_one($dirName){

			if(file_exists($dirName) && $handle=opendir($dirName)){

				while(false!==($item = readdir($handle))){
					if($item!= "." && $item != ".."){
						if(file_exists($dirName.'/'.$item) && is_dir($dirName.'/'.$item)){
							delFile($dirName.'/'.$item);
						}else{
							if(unlink($dirName.'/'.$item)){
								return true;
							}
						}
					}
				}
				closedir($handle);
			}
		}
		
		function delFile($dir)
		{
			
			if($dir=='' || strlen($dir)<5)
			{ return false;
				die;
			}
			if(strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
			   $dir = str_replace('/','\\',$dir);
			   $str = "rmdir /s/q " . $dir;
			} else {
				$dir = str_replace('\\','/',$dir);
				$str = "rm -rf " . $dir;
			}
			exec($str);
		}
	/****删除指定目录下所有文件 end****/

// 判断是否是手机号码	
function is_mobile( $text ) {
	$search = '/^0?1[3|4|5|6|7|8][0-9]\d{8}$/';
	if ( preg_match( $search, $text ) ) {
		return ( true );
	} else {
		return ( false );
	}
}
$re = [];
foreach ($arr as $key=>$v) {
    $re[$key]=$v;
    foreach ($arr_r as $v_v){

        if ($v['id']==$v_v['diy_id']){

            $re[$key]['clild']=$v_v;
        }
    }
}
/**
 * 重设键，转为array(key=>array())
 * @param array $arr
 * @param string $key
 * @return array
 */
function reset_by_key_admin($arr, $key) {
    $re = [];
    foreach ($arr as $v) {
        $re[$v[$key]] = $v;
    }

    return $re;
}

/**
 * 生成随机字符串
 * @param string $prefix
 * @return string
 */
function get_random($prefix = '') {
    return $prefix . base_convert(time() * 1000, 10, 36) . "_" . base_convert(microtime(), 10, 36) . uniqid();
}
/**
 * 从二维数组中取出自己要的KEY值
 * @param  array $arrData
 * @param string $key
 * @param $im true 返回逗号分隔
 * @return array
 */
function filter_value_admin($arrData, $key, $im = false) {
    $re = [];
    foreach ($arrData as $k => $v) {
        if (isset($v[$key]))
            $re[] = $v[$key];
    }
    if (!empty($re)) {
        $re = array_flip(array_flip($re));
        sort($re);
    }

    return $im ? implode(',', $re) : $re;
}
/**
 * 计算剩余天时分。
 * $unixEndTime string 终止日期的Unix时间
 * @author tangxinzhuan
 * @version 2016-10-28
 */
function timeRemaining($unixEndTime=0)
{
    if ($unixEndTime <= time()) { // 如果过了活动终止日期
        return '0天0时0分';
    }

    // 使用当前日期时间到活动截至日期时间的毫秒数来计算剩余天时分
    $time = $unixEndTime - time();

    $days = 0;
    if ($time >= 86400) { // 如果大于1天
        $days = (int)($time / 86400);
        $time = $time % 86400; // 计算天后剩余的毫秒数
    }

    $xiaoshi = 0;
    if ($time >= 3600) { // 如果大于1小时
        $xiaoshi = (int)($time / 3600);
        $time = $time % 3600; // 计算小时后剩余的毫秒数
    }

    $fen = (int)($time / 60); // 剩下的毫秒数都算作分

    return $days.'天'.$xiaoshi.'时'.$fen.'分';
}

function object2array($object) {
  if (is_object($object)) {
    foreach ($object as $key => $value) {
      $array[$key] = $value;
    }
  }
  else {
    $array = $object;
  }
  return $array;
} 